<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('客户档案管理')" />

<link rel="stylesheet" type="text/css" th:href="@{/plugin/layui/css/font/iconfont.css}" media="all"/>
<link rel="stylesheet" type="text/css" th:href="@{/plugin/layui/js/layui/css/layui.css}" media="all"/>
<link rel="stylesheet" type="text/css" th:href="@{/css/main.css}" media="all"/>

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline">
                        <label class="layui-form-label">客户类型</label>
                        <div class="layui-input-inline">
                            <select name="khlx">
                                <option value="" >==请选择==</option>
                                <option value="0" >收货人</option>
                                <option value="1" >承运人</option>
                                <option value="2" >仓库</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">客户编号</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="khbh" name="khbh" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">客户名称</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="khmc" name="khmc"  />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">激活状态</label>
                        <div class="layui-input-inline">
                            <div class="layui-input-inline">
                                <select name="sfjh">
                                    <option value="" >==请选择==</option>
                                    <option value="0" >不激活</option>
                                    <option value="1" >激活</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal" data-type="reload" id="search_button">搜索</a>
                    </div>
                    <div class="layui-inline inline-reset-btn">
                        <button type="reset" class="layui-btn layui-btn-primary" style="background-color: #1e9fff; color: white;">重置</button>
                    </div>
                </form>
                <!--顶部按钮展示区域 【 tpl-button 】 -->
                <div class="group-button tpl-button" id="toolbar"></div>
                <!--<div class="group-button" id="toolbar">

                    <a class="layui-btn layui-btn-sm layui-btn-normal add-btn">
                        <i class="layui-icon">&#x1005;</i> 添加
                    </a>
                    <a class="layui-btn layui-btn-sm layui-btn-normal edit-btn">
                        <i class="layui-icon">&#x1005;</i> 修改
                    </a>
                    <a class="layui-btn layui-btn-sm layui-btn-danger delBtn">
                        <i class="iconfont">&#xe626;</i> 启用/禁用
                    </a>
                    &lt;!&ndash; Single button &ndash;&gt;
                    <div class="btn-group">
                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                            多选操作 <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu">
                            <li><a href="#">多选删除</a></li>
                            <li><a href="#">多选打印</a></li>
                            <li><a href="#">明细表</a></li>
                            <li role="separator" class="divider"></li>
                            <li><a href="#">Separated link</a></li>
                        </ul>
                    </div>
                </div>-->
                <!--列表-->
                <section class="panel panel-padding layui-card-body" >
                    <div class="pro">
                        <table id="table"  class="table text-nowrap" style="word-break:break-all; word-wrap:break-word;"></table>

                    </div>
                </section>
            </div>
        </div>
    </div>
</div>

</body>


<script type="text/javascript" th:src="@{/plugin/layui/js/layui/layui.js}"></script>
<script type="text/javascript" th:src="@{/plugin/layui/js/version.js}"></script>
<script th:src="@{/plugin/layui/js/common.js}"></script>
<div th:include="public/public_js::public_js"></div>
<div th:include="public/public_btn::public_btn"></div>
<script th:inline="javascript">
    $(function () {
        console.log("我来了！！ ");
        $(".moreBtn").on("click",function () {
            $(".moreSearch").toggle();
        })
    });


    //	回车查询
    document.onkeydown = function(event) {
        e = event ? event : (window.event ? window.event : null);
        if (e.keyCode == 13) {
            //执行的方法
            $('#search_button').click();
        }
    };
    var functions = [[${functions}]];
    layui.use(['list','layer','zzpUtils','jquery','laydate','tablebutton'],function () {

        /* window.operateEvent ={
         "click .addAddress":function (e, value, row, index) {//增加地址
         console.info("增加地址");
         addAddressDialog(row.id);
         },

         "click .editRow":function (e, value, row, index) {
         console.info("sd");
         editDialog(row.id);
         },
         "click .jhBtn":function (e, value, row, index) {//激活
         jhBtn(row.id);
         },


         }*/

        var zzpUtils= layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate;
        tablebtn = layui.tablebutton;
        tablebtn.buildOnClick({
            type: 1,
            temp: $("#function_tpl"),
            functions: functions.headBtn,
            row: null,
            event: {
                searchEvent: function () {
                    console.log("点查询了");
                    zzpUtils.refreshTable("#table");
                },
                /*新增*/
                addEvent: function (data) {
                    add();
                },
                /*编辑*/
                editEvent: function (data) {
                    if (data.row != undefined) {
                        console.info(data.row.id);
                        editDialog(data.row.id);
                    }
                },
                //查看
                getEvent: function (data) {
                    detail(data.row)
                },
                //禁用
                disableEvent: function (data) {
                    disableEvent(data.row)
                },
                //启用
                enableEvent: function (data) {
                    enableEvent(data.row)
                },
            }
        })

        /*   function jhBtn(id) {
         var ids=new Array(id);
         zzpUtils.confirm("是否激活",function (index) {
         zzpUtils.action({
         url:"/wmsCustomerFiles/activation",
         data: JSON.stringify({ids:ids}),
         success:function (data) {
         setTimeout(function(){
         top.layer.msg(data.title+","+data.message);
         zzpUtils.refreshTable("#table");
         //刷新父页面
         },500);
         },error: function (xhr, textStatus) {
         console.log(textStatus);
         console.log(xhr)
         }
         })
         })
         }*/
        function editDialog(id){
            zzpUtils.dialog({
                title:"修改客户档案",
                type:2,
                content: "/wmsCustomerFileRouter/toEditCustomerFile?id="+id,
                end: function () {//添加成功后刷新
                    zzpUtils.refreshTable("#table");
                }

            });
        }

        laydate.render({
            elem: '#test5'
            ,theme: '#20a0ff'
        })
        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            pagination:true,
            isOperate: true,
            url: '/wmsCustomerFiles/list',
            columns: [/*{
                field: '',
                checkbox: true
            },*/{
                field: 'show_khlx',
                title: '客户类型'
            },{
                field: 'khbh',
                title: '客户编号'
            },{
                field: 'khmc',
                title: '客户名称'
            },{
                field: 'dz',
                title: '客户地址'
            },{
                field: 'lxrxm',
                title: '联系人'
            },{
                field: 'lxrdh',
                title: '联系电话'
            },{
                field: 'show_sfjh',
                title: '激活状态'
            }/*,{
             field:'caozuo',
             title: '操作',
             /!* events:operateEvent,*!/
             formatter:operateFormatter
             }*/],
            queryParams: function () {//查询条件
                return  zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (row,index) {
                return "这里就没有确定过11";
            },
            /*定义表格右侧按钮*/
            operateFormatter: operateFormatter

        });


        /*function operateFormatter(value, row, index) {
         return [
         '<a class="layui-btn layui-btn-primary layui-btn-xs addAddress" >增加地址</a>',
         '<a class="layui-btn layui-btn-xs editRow" >编辑</a>',
         '<a class="layui-btn layui-btn-danger layui-btn-xs jhBtn ">启用/禁用</a>'
         ].join('')*/


        $(".inline-search-btn").on('click',function () {
            zzpUtils.refreshTable("#table");
        });
        //禁用
        function disableEvent(row){
            /*var ids = $.map($rows,function (row) {
             return row.id;
             })*/
            console.info(row);
            var ids=[row.id];
            zzpUtils.confirm("是否禁用",function (index) {
                zzpUtils.action({
                    url:"/wmsCustomerFiles/cancel",
                    data: JSON.stringify({ids:ids}),
                    success:function (data) {
                        setTimeout(function(){
                            top.layer.msg(data.title+","+data.message);
                            zzpUtils.refreshTable("#table");
                            //刷新父页面
                        },500);
                    },error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                })
            })
        }

        //启用
        function enableEvent(row){

            /* var ids = $.map($rows,function (row) {
             return row.id;
             })*/
            var ids=[row.id];
            zzpUtils.confirm("是否激活",function (index) {
                zzpUtils.action({
                    url:"/wmsCustomerFiles/activation",
                    data: JSON.stringify({ids:ids}),
                    success:function (data) {
                        setTimeout(function(){
                            top.layer.msg(data.title+","+data.message);
                            zzpUtils.refreshTable("#table");
                            //刷新父页面
                        },500);
                    },error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                })
            })
        }
        /*  $(".delBtn").on('click',function () {
         var $rows = $table.bootstrapTable('getSelections');
         if($rows.length == 0){
         layer.msg("请选择一条进行激活");
         }else{
         var ids = $.map($rows,function (row) {
         return row.id;
         })
         alert(ids.join(','));
         zzpUtils.confirm("是否激活",function (index) {
         zzpUtils.action({
         url:"/wmsCustomerFiles/activation",
         data: JSON.stringify({ids:ids}),
         success:function (data) {
         setTimeout(function(){
         top.layer.msg(data.title+","+data.message);
         zzpUtils.refreshTable("#table");
         //刷新父页面
         },500);
         },error: function (xhr, textStatus) {
         console.log(textStatus);
         console.log(xhr)
         }
         })
         })
         }
         })*/

        /*$(".edit-btn").on('click',function () {
         alert(".edit-btn");
         var $rows = $table.bootstrapTable('getSelections');
         if($rows.length != 1){
         layer.msg("请选择一条进行编辑");
         }else{
         var id = $.map($rows,function (row) {
         return row.id;
         })
         zzpUtils.dialog({
         title: "修改客户档案",
         type: 2,
         content: "/wmsCustomerFileRouter/toEditCustomerFile?id=" + id,
         end: function () {//添加成功后刷新
         zzpUtils.refreshTable("#table");
         }

         })
         }


         })*/
        function add() {
            zzpUtils.dialog({
                title:"添加客户档案",
                type:2,
                content: "/wmsCustomerFileRouter/toAddCustomerFile",
                btn:[],
                end: function () {//添加成功后刷新
                    zzpUtils.refreshTable("#table");
                }

            });
        }

        function  detail(row){
            if(row.khlx==0){//收货人
                zzpUtils.dialog({
                    title:"收货地址管理",
                    type:2,
                    content: "/wmsCustomerFileRouter/toConsigneeDetail?id="+row.id,
                    btn:[],
                    end: function () {//添加成功后刷新
                        zzpUtils.refreshTable("#table");
                    }
                });

            }else if(row.khlx==1){//承运人
                zzpUtils.dialog({
                    title:"所属车辆管理",
                    type:2,
                    content: "/wmsCustomerFileRouter/toCarrierDetail?id="+row.id,
                    btn:[],
                    end: function () {//添加成功后刷新
                        zzpUtils.refreshTable("#table");
                    }
                });
            }else if(row.khlx==2){//仓库
                zzpUtils.dialog({
                    title:"所属仓库管理",
                    type:2,
                    content: "/wmsCustomerFileRouter/toWarehouseDetail?id="+row.id,
                    btn:[],
                    end: function () {//添加成功后刷新
                        zzpUtils.refreshTable("#table");
                    }
                });
            }

        }


        /*表格右侧按钮*/
        function operateFormatter(value, row, index) {
            /* var button = '<a class="tooltip2" id="tooltip' + row.id + '" data-tooltip-content="#tool' + row.id + '" id="btn_start"><i class="layui-icon layui-icon-more"></i></a>'
             + '<div class="tooltip_templates">'
             + '<span id="tool' + row.id + '">';*/
          /*  var button = '<a class="tooltip2" id="tooltip' + row.id + '" data-tooltip-content="#tool' + row.id + '">更多</a>'
                + '<div class="tooltip_templates"><span id="tool' + row.id + '">';*/
            var button ="";
            for (var i = 0; i < functions.tableBtn.length; i++) {
                var item = functions.tableBtn[i];
                var btn = '<a class="layui-btn layui-btn-sm layui-btn-normal" lay-event="' + functions.tableBtn[i].event + '">'
                    + functions.tableBtn[i].name
                    + '</a>';
                /*     button += btn;*/

                if (row.sfjh == 0 && functions.tableBtn[i].name == '启用') {//未激活
                    button +=btn = '<button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="' + item.event + '">'
                        + item.name
                        + '</button>';
                }else if (row.sfjh == 0 && functions.tableBtn[i].name == '禁用') {//未激活
                    button += btn = '<button class="layui-btn layui-btn-sm layui-btn-disabled" disabled lay-event="' + item.event + '">'
                        + item.name
                        + '</button>';
                }else if (row.sfjh == 0 && functions.tableBtn[i].name == '编辑') {//未激活
                    button += btn = '<button class="layui-btn layui-btn-sm layui-btn-disabled" disabled lay-event="' + item.event + '">'
                        + item.name
                        + '</button>';
                }else if (row.sfjh == 0 && functions.tableBtn[i].name == '查看') {//未激活
                    button += btn = '<button class="layui-btn layui-btn-sm layui-btn-disabled" disabled lay-event="' + item.event + '">'
                        + item.name
                        + '</button>';
                } else if(row.sfjh == 1 && functions.tableBtn[i].name == '启用'){//激活
                    button += btn = '<button class="layui-btn layui-btn-sm layui-btn-disabled" disabled lay-event="' + item.event + '">'
                        + item.name
                        + '</button>';
                } else if(row.sfjh == 1 && functions.tableBtn[i].name == '禁用'){//激活
                    button +=btn = '<button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="' + item.event + '">'
                        + item.name
                        + '</button>';
                } else if(row.sfjh == 1 && functions.tableBtn[i].name == '编辑'){//激活
                    button +=btn = '<button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="' + item.event + '">'
                        + item.name
                        + '</button>';
                } else if(row.sfjh == 1 && functions.tableBtn[i].name == '查看'){//激活
                    button +=btn = '<button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="' + item.event + '">'
                        + item.name
                        + '</button>';
                }

                /*
                 if (row.sfyx == 1 && functions.tableBtn[i].name == '编辑') {
                 button +=btn = '<button class="layui-btn layui-btn-sm layui-btn-warm" lay-event="' + item.event + '">'
                 + item.name
                 + '</button>';
                 }else if(row.sfyx == 0 && functions.tableBtn[i].name == '编辑'){
                 button += btn = '<button class="layui-btn layui-btn-sm layui-btn-disabled" disabled lay-event="' + item.event + '">'
                 + item.name
                 + '</button>';
                 }
                 if (row.sfyx == 1 && functions.tableBtn[i].name == '库位组') {
                 button +=btn = '<button class="layui-btn layui-btn-sm layui-btn-warm" lay-event="' + item.event + '">'
                 + item.name
                 + '</button>';
                 }else if(row.sfyx == 0 && functions.tableBtn[i].name == '库位组'){
                 button += btn = '<button class="layui-btn layui-btn-sm layui-btn-disabled" disabled lay-event="' + item.event + '">'
                 + item.name
                 + '</button>';
                 }

                 if (row.sfyx==0 && functions.tableBtn[i].name == '清单') {//不存在 物料清单
                 button += btn = '<button class="layui-btn layui-btn-sm layui-btn-disabled" disabled lay-event="' + item.event + '">'
                 + item.name
                 + '</button>';

                 } else if (row.sfyx==1 && row.bom == 1 && functions.tableBtn[i].name == '清单' ) {//存在 物料清单
                 button +=btn = '<button class="layui-btn layui-btn-sm layui-btn-warm" lay-event="' + item.event + '">'
                 + item.name
                 + '</button>';
                 }else  if(row.sfyx==1 && row.bom == 0 && functions.tableBtn[i].name == '清单'){
                 button += btn = '<button class="layui-btn layui-btn-sm layui-btn-disabled" disabled lay-event="' + item.event + '">'
                 + item.name
                 + '</button>';
                 }

                 if (row.sfyx == 1 && functions.tableBtn[i].name == '启用') {//无效
                 button += btn = '<button class="layui-btn layui-btn-sm layui-btn-disabled" disabled lay-event="' + item.event + '">'
                 + item.name
                 + '</button>';
                 } else if (row.sfyx == 0 && functions.tableBtn[i].name == '启用') {//无效
                 button +=btn = '<button class="layui-btn layui-btn-sm layui-btn-warm" lay-event="' + item.event + '">'
                 + item.name
                 + '</button>';
                 }

                 if(row.sfyx == 0 && functions.tableBtn[i].name == '禁用'){//无效
                 button += btn = '<button class="layui-btn layui-btn-sm layui-btn-disabled" disabled lay-event="' + item.event + '">'
                 + item.name
                 + '</button>';
                 }else if(row.sfyx == 1 && functions.tableBtn[i].name == '禁用'){//有效
                 button += btn = '<button class="layui-btn layui-btn-sm layui-btn-warm" lay-event="' + item.event + '">'
                 + item.name
                 + '</button>';
                 }*/

            }
            button += '</span>'
                + '</div>';
            return button;

        }


    });
</script>
</html>